﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace AllegroIWI
{
	public class Histogram
	{
		public int[] R { get; set; }
		public int[] G { get; set; }
		public int[] B { get; set; }
		public int[] RGB { get; set; }
		public long rTotal { get; set; }
		public long gTotal { get; set; }
		public long bTotal { get; set; }
		public double Total { get; set; }
		public Histogram() { }
		public Histogram(Bitmap bmp)
		{
			R = new int[256];
			B = new int[256];
			G = new int[256];
			RGB = new int[256];
			for (int i = 0; i < bmp.Width; i++)
			{
				for (int j = 0; j < bmp.Height; j++)
				{
					Color pixel = bmp.GetPixel(i,j);
					int rValue = pixel.R;
					int gValue = pixel.G;
					int bValue = pixel.B;
					R[rValue]++;
					G[gValue]++;
					B[bValue]++;
					rTotal+=rValue;
					gTotal+=gValue;
					bTotal+=bValue;
					int rgb = (int)(0.3 * rValue + 0.6 * gValue + 0.1 * bValue);
					RGB[rgb]++;
				}
			}
			CountTotal();
		}

		private void CountTotal()
		{
			Total = 0;
			for (int i = 0; i < 256; i++)
			{
				Total += 0.3 * R[i] + 0.6 * G[i] + 0.1 * B[i];
			}
			double total = 0.3 * rTotal + 0.6 * gTotal + 0.1 * bTotal;
			//System.Console.WriteLine(Total);
		}

		//public static double ObliczOdlegloscHistogramow(Histogram h1, Histogram h2)
		//{
		//    double total = 0;
		//    for (int i = 0; i < 256; i++)
		//    {
		//        double rValue = Math.Abs(h1.R[i] - h2.R[i]);
		//        double gValue = Math.Abs(h1.G[i] - h2.G[i]);
		//        double bValue = Math.Abs(h1.B[i] - h2.B[i]);
		//        total = 0.3 * rValue + 0.6 * gValue + 0.1 * bValue;
		//    }
		//    return total;
		//}

		//public static double ObliczOdleglosciHistogramow(Histogram h1, Histogram h2)
		//{
		//    return Math.Abs(h1.Total - h2.Total);
		//}


	}
}
